//
//@File    :	4.20_ptrstr.cpp
//@Time    :	2021/08/04 17:01:46
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	using pointer to strings
//

#include <cstring>
#include <iostream>

int main()
{
    using namespace std;
    char animal[20] = "bear";
    const char * bird = "wren";
    char * ps;

    cout<<animal<<" and ";
    cout<<bird<<"\n";

    cout<<"Enter a kind of animal: ";
    cin>>animal;

    ps = animal;
    cout<<ps<<"!\n";
    cout<<"Before using strcpy():\n";
    cout<<animal<<" st "<<(int*)animal<<endl;
    cout<<ps<<" at "<<(int*)ps<<endl;

    ps = new char[strlen(animal)+1];
    strcpy(ps,animal);
    cout<<"After using strcpy():\n";
    cout<<animal<<" at "<<(int*)animal<<endl;
    cout<<ps<<" at "<<(int*)ps<<endl;
    delete [] ps;

    system("pause");
    return 0;
}